<template>
  <div class="app-container">
    <!-- 查询模块 -->
    <!-- <div class="formDiv"> -->
    <div class="receivableSheet">
      <el-form ref="form" :inline="true" :model="form" label-width="130px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="订单号">
              <el-input v-model="form.order_sn" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="手机号">
              <el-input v-model="form.phone" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="plus会员卡名称">
              <el-input v-model="form.card_name" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="商户名称">
              <el-input v-model="form.shop_name" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="订单状态">
              <el-select v-model="form.order_status" placeholder="请选择" clearable>
                <el-option
                  v-for="(item,index) in orderStatusList"
                  :key="index"
                  :label="item.name"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="下单时间">
              <el-date-picker
                v-model="form.order_time"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="4" :offset="11"> -->
          <!--  :span="3" :offset="8" -->
          <el-col :span="4" :offset="6">
            <el-button type="primary" @click="searchList()">查询</el-button>
            <el-button type="primary" @click="handleExport()">导出</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>

    <!-- 主页列表 -->
    <div class="listDiv" v-loading="tableLoading">
      <!-- table列表 -->
      <el-table :data="tableData" style="width: 100%">
        <el-table-column fixed type="index" label="编号" width="80px" align="center"></el-table-column>
        <el-table-column prop="order_sn" label="订单号" align="center"></el-table-column>
        <el-table-column prop="nickname" label="昵称" align="center"></el-table-column>
        <el-table-column prop="realname" label="姓名" align="center"></el-table-column>
        <el-table-column prop="phone" label="手机号" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.phone | phonereg}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="card_name" label="plus会员卡名称" align="center"></el-table-column>
        <el-table-column prop="shop_name" label="商户名称" align="center"></el-table-column>
        <el-table-column prop="order_status_name" label="订单状态" align="center"></el-table-column>
        <el-table-column prop="pay_price" label="订单金额" align="center"></el-table-column>
        <el-table-column prop="payment" label="支付方式" align="center">
          <template slot-scope="scope">{{scope.row.payment | paymentType}}</template>
        </el-table-column>
        <el-table-column prop="order_time" label="下单时间" align="center">
          <template slot-scope="scope">{{ scope.row.order_time|data}}</template>
        </el-table-column>
        <el-table-column prop="serial_number" label="序列码" align="center"></el-table-column>
        <el-table-column prop="remark" label="备注" align="center"></el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <!-- 查看按钮 -->
            <el-button type="text" size="mini" @click="toRoutes('plusOrderInfo',scope.row.id)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="form.page"
            :page-sizes="page_sizes"
            :page-size="form.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page_totals"
          ></el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { plusOrderList, plusCardInfo } from "@/api/orderMange";
import commonFn from "@/utils/common";

export default {
  name: "plusOrderList",
  data() {
    return {
      // loading层
      tableLoading: false,

      // 提交form
      form: {
        page: 1,
        pagesize: 10,
        card_name: "",
        order_time: "",
        order_sn: "",
        phone: "",
        shop_name: "",
        order_status: ""
      },
      orderStatusList: [
        { name: "全部", value: 0 },
        { name: "未支付", value: 1 },
        { name: "已支付", value: 2 }
      ],
      // 主页列表显示
      tableData: [],
      // 分页
      page_sizes: [10, 30, 50, 100],
      page_totals: 60
    };
  },
  filters: {
    data: function(data) {
      var d = new Date(data * 1000);
      var year = d.getFullYear();
      var month = d.getMonth() + 1;
      var date = d.getDate();
      var hour = d.getHours();
      var minute = d.getMinutes();
      var second = d.getSeconds();
      return (
        year +
        "-" +
        month +
        "-" +
        date +
        " " +
        hour +
        ":" +
        minute +
        ":" +
        second
      );
    },
    paymentType(e) {
      switch (e) {
        case 1:
          return "支付宝";
          break;
        case 2:
          return "微信";
          break;
        default:
          // return "暂无";
          break;
      }
    }
  },
  mounted() {
    this.getList(this.form);
  },
  methods: {
    //获取列表
    getList(e) {
      this.tableLoading = true;
      plusOrderList(e)
        .then(res => {
          // console.log(res)
          if (res.data.code == 200) {
            this.tableData = res.data.data;
            this.page_totals = res.data.page_totals;
          } else {
            this.$message({
              showClose: true,
              message: res.data.msg,
              type: "warning"
            });
          }
          this.tableLoading = false;
        })
        .catch(res => {
          this.errorStatus(res.msg);
          this.tableLoading = false;
        });
    },
    handleExport() {
      plusCardInfo({
        order_sn: this.form.order_sn,
        phone: this.form.phone,
        card_name: this.form.card_name,
        order_time: this.form.order_time,
        shop_name: this.form.shop_name,
        order_status: this.form.order_status
      })
        .then(res => {
          commonFn.downFile("plus会员卡订单", res);
        })
        .catch(err => {
          this.errorStatus(err);
        });
    },
    //搜索
    searchList() {
      this.form.page = 1;
      this.getList(this.form);
    },
    // 路由跳转
    toRoutes(e, Id) {
      let route = { name: e, query: { id: Id } };
      this.$router.push(route);
    },
    //改变页面条数
    handleSizeChange(val) {
      this.form.pagesize = val;
      this.getList(this.form);
    },
    //选择页数
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form);
    }
  }
};
</script>
<style scoped>
/* 分页 */
.pagesCon {
  height: 40px;
  margin-top: 20px;
}
.pagesCon > div {
  float: right;
}
/* 表单样式修改 */
/* .el-range-editor--medium.el-input__inner {
  width: 236px;
} */
.switchBtn {
  color: #ff4949;
}
/* .el-date-editor.el-input__inner {
    width: 220px !important;
} */
.alignRight {
  text-align: right;
}
</style>